#ifndef H_SUBJECT_H
#define H_SUBJECT_H
#include <vector>
#include "Observer.h"
namespace ObserverMode
{
    class Subject
    {
    public:
        void add(Observer* ob)
        {
            _observerArr.push_back(ob);
            std::cout<<"add _observerArr"<<_observerArr.size()<<std::endl;
        }

        void remove(Observer* ob)
        {
            auto itor = std::find(_observerArr.begin(),_observerArr.end(),ob);
            if(itor!=_observerArr.end())
                _observerArr.erase(itor);
        }

        virtual void notifyObserver() = 0;
    protected:
        std::vector<Observer*> _observerArr;
    };
}
#endif

// ObserverMode::Subject* subject = new ObserverMode::ConcreateSubject();
// ObserverMode::Observer* observer1 = new ObserverMode::ConcreteObserver1;
// ObserverMode::Observer* observer2 = new ObserverMode::ConcreteObserver2;
// subject->add(observer1);
// subject->add(observer2);
// subject->notifyObserver();